package com.chennan.leading.common.distributedno.model;

import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * @author chennan
 * @createTime 2022年03月24日 17:14:00
 */
@Data
@Accessors(chain = true)
@Builder
public class BasicGenerateNoParam {
    /**
     * 分布式锁key
     */
    private String distributedLockKey;

    /**
     * no生成的前缀 默认 LEADING
     */
    private String prefix;

    /**
     * 格式化类型 默认%08d
     */

    private String formatType;
    /**
     * 过期时间单位 默认秒
     */

    private TimeUnit timeUnit;

    /**
     * 超时时间 默认90000L
     */
    private Long timeout;

    /**
     * no在redis的key
     */

    private String redisKeyNo;

    /**
     * 最大限制 默认100_000_000L
     */
    private Long maxNo;

    /**
     * 是否是纯数字编号 默认否
     */
    private Boolean numberNoType;

    public String getFormatType() {
        if (Objects.isNull(formatType)) {
            this.formatType = "%08d";
        }
        return formatType;
    }

    public TimeUnit getTimeUnit() {
        if (Objects.isNull(timeUnit)) {
            this.timeUnit = TimeUnit.SECONDS;
        }
        return timeUnit;
    }

    public Long getTimeout() {
        if (Objects.isNull(timeout)) {
            this.timeout = 90000L;
        }
        return timeout;
    }

    public Long getMaxNo() {
        if (Objects.isNull(maxNo)) {
            this.maxNo = 100_000_000L;
        }
        return maxNo;
    }

    public String getPrefix() {
        if (Objects.isNull(prefix)) {
            this.prefix = "";
        }
        return prefix;
    }

    public Boolean getNumberNoType() {
        if (Objects.isNull(numberNoType)) {
            numberNoType = false;
        }
        return numberNoType;
    }
}
